package dk.pun.aot.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.uibinder.client.UiTemplate;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

import dk.pun.aot.client.dice.DicePoolType;
import dk.pun.aot.client.dice.DiceRoll;
import dk.pun.aot.client.dice.DiceRollType;
import dk.pun.aot.client.dice.DiceRoller;
import dk.pun.aot.client.widget.DiceRollHistoryPanel;
import dk.pun.aot.client.widget.DiceRollPopup;
import dk.pun.aot.shared.character.CharacterData;
import dk.pun.aot.shared.character.CharacterQualities;
import dk.pun.aot.shared.character.CharacterSkills;
import dk.pun.aot.shared.character.MovementRates;
import dk.pun.aot.shared.character.QualityScoreVerifier;
import dk.pun.aot.shared.character.QualityType;
import dk.pun.aot.shared.character.SkillRankVerifier;
import dk.pun.aot.shared.character.SkillType;

public class ViewCharacterViewImpl extends Composite implements ViewCharacterView {
	
	private static ViewCharacterViewUiBinder uiBinder = GWT.create(ViewCharacterViewUiBinder.class);

	@UiTemplate("ViewCharacterView.ui.xml")
	interface ViewCharacterViewUiBinder extends UiBinder<Widget, ViewCharacterViewImpl> {}

	@UiField TextBox strengthScore;
	@UiField Label strengthScoreError;
	@UiField Button strengthDicePool;
	@UiField TextBox agilityScore;
	@UiField Label agilityScoreError;
	@UiField Button agilityDicePool;
	@UiField TextBox conditioningScore;
	@UiField Label conditioningScoreError;
	@UiField Button conditioningDicePool;
	@UiField TextBox vitalityScore;
	@UiField Label vitalityScoreError;
	@UiField Button vitalityDicePool;
	@UiField TextBox disciplineScore;
	@UiField Label disciplineScoreError;
	@UiField Button disciplineDicePool;
	@UiField TextBox intelligenceScore;
	@UiField Label intelligenceScoreError;
	@UiField Button intelligenceDicePool;
	@UiField TextBox charismaScore;
	@UiField Label charismaScoreError;
	@UiField Button charismaDicePool;
	@UiField TextBox athleticismScore;
	@UiField Button athleticismDicePool;
	@UiField TextBox physicalAcumenScore;
	@UiField Button physicalAcumenDicePool;
	@UiField TextBox fitnessScore;
	@UiField Button fitnessDicePool;
	@UiField TextBox willScore;
	@UiField Button willDicePool;
	@UiField TextBox wisdomScore;
	@UiField Button wisdomDicePool;
	@UiField TextBox witScore;
	@UiField Button witDicePool;
	@UiField TextBox presenceScore;
	@UiField Button presenceDicePool;
	@UiField TextBox reactionScore;
	@UiField Button reactionDicePool;
	@UiField TextBox physisScore;
	@UiField TextBox defenseRatingScore;
	@UiField TextBox movementSwim;
	@UiField TextBox movementCrawl;
	@UiField TextBox movementMonkeyRun;
	@UiField TextBox movementWalk;
	@UiField TextBox movementRun;
	@UiField TextBox movementSprint;
	@UiField TextBox movementFly;
	@UiField TextBox healthPool;
	@UiField TextBox healthCurrent;
	@UiField TextBox endurancePool;
	@UiField TextBox enduranceCurrent;
	@UiField HasWidgets diceRollHistory;
	@UiField TextBox historyRank;
	@UiField Button historyDicePool;
	@UiField TextBox sociologyRank;
	@UiField Button sociologyDicePool;
	@UiField TextBox theologyRank;
	@UiField Button theologyDicePool;
	@UiField TextBox lawRank;
	@UiField Button lawDicePool;

	private Presenter presenter;
	private CharacterQualities characterQualities;
	private CharacterSkills characterSkills;
	private DiceRoller diceRoller;
	private MovementRates movementRates;
	
	public ViewCharacterViewImpl(DiceRollHistoryPanel diceRollHistoryPanel) {
		initWidget(uiBinder.createAndBindUi(this));
		this.initQualityTextBox(strengthScore, 1, false);
		this.initQualityTextBox(agilityScore, 2, false);
		this.initQualityTextBox(conditioningScore, 3, false);
		this.initQualityTextBox(vitalityScore, 4, false);
		this.initQualityTextBox(disciplineScore, 5, false);
		this.initQualityTextBox(intelligenceScore, 6, false);
		this.initQualityTextBox(charismaScore, 7, false);
		this.initQualityTextBox(athleticismScore, -1, true);
		this.initQualityTextBox(physicalAcumenScore, -1, true);
		this.initQualityTextBox(fitnessScore, -1, true);
		this.initQualityTextBox(willScore, -1, true);
		this.initQualityTextBox(wisdomScore, -1, true);
		this.initQualityTextBox(witScore, -1, true);
		this.initQualityTextBox(presenceScore, -1, true);
		this.initQualityTextBox(reactionScore, -1, true);
		this.initQualityTextBox(physisScore, -1, true);
		this.initQualityTextBox(defenseRatingScore, -1, true);
		this.initQualityTextBox(movementSwim, -1, true);
		this.initQualityTextBox(movementCrawl, -1, true);
		this.initQualityTextBox(movementMonkeyRun, -1, true);
		this.initQualityTextBox(movementWalk, -1, true);
		this.initQualityTextBox(movementRun, -1, true);
		this.initQualityTextBox(movementSprint, -1, true);
		this.initQualityTextBox(movementFly, -1, true);
		this.initQualityTextBox(healthPool, -1, true);
		this.initQualityTextBox(healthCurrent, -1, true);
		this.initQualityTextBox(endurancePool, -1, true);
		this.initQualityTextBox(enduranceCurrent, -1, true);
		this.initSkillTextBox(historyRank, 9);
		this.initSkillTextBox(sociologyRank, 10);
		this.initSkillTextBox(theologyRank, 11);
		this.initSkillTextBox(lawRank, 12);

		this.diceRollHistory.add(diceRollHistoryPanel);
		
		this.diceRoller = new DiceRoller();
		this.movementRates = new MovementRates();
	}

	private void initQualityTextBox(TextBox textBox, int index, boolean readOnly) {
		textBox.setMaxLength(3);
		textBox.setVisibleLength(3);
		textBox.setTabIndex(index);
		textBox.setReadOnly(readOnly);
	}

	private void initSkillTextBox(TextBox textBox, int index) {
		textBox.setMaxLength(2);
		textBox.setVisibleLength(2);
		textBox.setTabIndex(index);
	}
	
	@Override
	public void setPresenter(Presenter presenter) {
		this.presenter = presenter;
	}
	
	@Override
	public void setCharacterData(CharacterData characterData) {
		this.characterQualities = characterData.getQualities();
		this.updateCoreQualities();
		this.updateQualities();
		this.characterSkills = characterData.getSkills();
	}
		
	@UiHandler("strengthScore")
	public void strengthScoreChangeHandler(ChangeEvent event) {
		String value = this.strengthScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.STRENGTH, QualityScoreVerifier.verify(value));
			this.strengthScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.STRENGTH, this.characterQualities.getQualityScore(QualityType.STRENGTH));
			}
		} catch (IllegalArgumentException exception) {
			this.strengthScoreError.setText(exception.getMessage());
		}
	}
	
	@UiHandler("agilityScore")
	public void agilityScoreChangeHandler(ChangeEvent event) {
		String value = this.agilityScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.AGILITY, QualityScoreVerifier.verify(value));
			this.agilityScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.STRENGTH, this.characterQualities.getQualityScore(QualityType.STRENGTH));
			}
		} catch (IllegalArgumentException exception) {
			this.agilityScoreError.setText(exception.getMessage());
		}
	}
		
	@UiHandler("conditioningScore")
	public void conditioningScoreChangeHandler(ChangeEvent event) {
		String value = this.conditioningScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.CONDITIONING, QualityScoreVerifier.verify(value));
			this.conditioningScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.CONDITIONING, this.characterQualities.getQualityScore(QualityType.CONDITIONING));
			}
		} catch (IllegalArgumentException exception) {
			this.conditioningScoreError.setText(exception.getMessage());
		}
	}

	@UiHandler("vitalityScore")
	public void vitalityScoreChangeHandler(ChangeEvent event) {
		String value = this.vitalityScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.VITALITY, QualityScoreVerifier.verify(value));
			this.vitalityScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.VITALITY, this.characterQualities.getQualityScore(QualityType.VITALITY));
			}
		} catch (IllegalArgumentException exception) {
			this.vitalityScoreError.setText(exception.getMessage());
		}
	}
	
	@UiHandler("disciplineScore")
	public void disciplineScoreChangeHandler(ChangeEvent event) {
		String value = this.disciplineScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.DISCIPLINE, QualityScoreVerifier.verify(value));
			this.disciplineScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.DISCIPLINE, this.characterQualities.getQualityScore(QualityType.DISCIPLINE));
			}
		} catch (IllegalArgumentException exception) {
			this.disciplineScoreError.setText(exception.getMessage());
		}
	}
		
	@UiHandler("intelligenceScore")
	public void intelligenceScoreChangeHandler(ChangeEvent event) {
		String value = this.intelligenceScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.INTELLIGENCE, QualityScoreVerifier.verify(value));
			this.intelligenceScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.INTELLIGENCE, this.characterQualities.getQualityScore(QualityType.INTELLIGENCE));
			}
		} catch (IllegalArgumentException exception) {
			this.intelligenceScoreError.setText(exception.getMessage());
		}
	}
	
	@UiHandler("charismaScore")
	public void chrismaScoreChangeHandler(ChangeEvent event) {
		String value = this.charismaScore.getValue();
		try {
			this.characterQualities.setCoreQualityScore(QualityType.CHARISMA, QualityScoreVerifier.verify(value));
			this.charismaScoreError.setText("");
			this.updateQualities();
			if (this.presenter != null) {
				this.presenter.onCoreQualityUpdated(QualityType.CHARISMA, this.characterQualities.getQualityScore(QualityType.CHARISMA));
			}
		} catch (IllegalArgumentException exception) {
			this.charismaScoreError.setText(exception.getMessage());
		}
	}
	
	@UiHandler("strengthDicePool")
	public void rollStrength(ClickEvent event) {
		this.showDiceRoll("Strength", this.characterQualities.getQualityScore(QualityType.STRENGTH), 0, DiceRollType.QUALITY);
	}

	@UiHandler("agilityDicePool")
	public void rollAgility(ClickEvent event) {
		this.showDiceRoll("Agility", this.characterQualities.getQualityScore(QualityType.AGILITY), 0, DiceRollType.QUALITY);
	}

	@UiHandler("conditioningDicePool")
	public void rollConditioning(ClickEvent event) {
		this.showDiceRoll("Conditioning", this.characterQualities.getQualityScore(QualityType.CONDITIONING), 0, DiceRollType.QUALITY);
	}

	@UiHandler("vitalityDicePool")
	public void rollVitality(ClickEvent event) {
		this.showDiceRoll("Vitality", this.characterQualities.getQualityScore(QualityType.VITALITY), 0, DiceRollType.QUALITY);
	}

	@UiHandler("disciplineDicePool")
	public void rollDiscipline(ClickEvent event) {
		this.showDiceRoll("Discipline", this.characterQualities.getQualityScore(QualityType.DISCIPLINE), 0, DiceRollType.QUALITY);
	}

	@UiHandler("intelligenceDicePool")
	public void rollIntelligence(ClickEvent event) {
		this.showDiceRoll("Intelligence", this.characterQualities.getQualityScore(QualityType.INTELLIGENCE), 0, DiceRollType.QUALITY);
	}

	@UiHandler("charismaDicePool")
	public void rollCharisma(ClickEvent event) {
		this.showDiceRoll("Charisma", this.characterQualities.getQualityScore(QualityType.CHARISMA), 0, DiceRollType.QUALITY);
	}

	@UiHandler("athleticismDicePool")
	public void rollAthleticism(ClickEvent event) {
		this.showDiceRoll("Athleticism", this.characterQualities.getQualityScore(QualityType.ATHLETICISM), 0, DiceRollType.QUALITY);
	}

	@UiHandler("physicalAcumenDicePool")
	public void rollPhysicalAcumen(ClickEvent event) {
		this.showDiceRoll("Physical Acumen", this.characterQualities.getQualityScore(QualityType.PHYSICAL_ACUMEN), 0, DiceRollType.QUALITY);
	}

	@UiHandler("fitnessDicePool")
	public void rollFitness(ClickEvent event) {
		this.showDiceRoll("Fitness", this.characterQualities.getQualityScore(QualityType.FITNESS), 0, DiceRollType.QUALITY);
	}

	@UiHandler("willDicePool")
	public void rollWill(ClickEvent event) {
		this.showDiceRoll("Will", this.characterQualities.getQualityScore(QualityType.WILL), 0, DiceRollType.QUALITY);
	}

	@UiHandler("wisdomDicePool")
	public void rollWisdom(ClickEvent event) {
		this.showDiceRoll("Wisdom", this.characterQualities.getQualityScore(QualityType.WISDOM), 0, DiceRollType.QUALITY);
	}

	@UiHandler("witDicePool")
	public void rollWit(ClickEvent event) {
		this.showDiceRoll("Wit", this.characterQualities.getQualityScore(QualityType.WIT), 0, DiceRollType.QUALITY);
	}

	@UiHandler("presenceDicePool")
	public void rollPresence(ClickEvent event) {
		this.showDiceRoll("Presence", this.characterQualities.getQualityScore(QualityType.PRESENCE), 0, DiceRollType.QUALITY);
	}

	@UiHandler("reactionDicePool")
	public void rollReaction(ClickEvent event) {
		this.showDiceRoll("Reaction", this.characterQualities.getQualityScore(QualityType.REACTION), 0, DiceRollType.QUALITY);
	}

	@UiHandler("historyRank")
	public void historyRankChangeHandler(ChangeEvent event) {
		String value = this.historyRank.getValue();
		try {
			this.characterSkills.setSkillRank(SkillType.HISTORY, SkillRankVerifier.verify(value));
			this.updateSkills(SkillType.HISTORY);
			if (this.presenter != null) {
				this.presenter.onSkillUpdated(SkillType.HISTORY, this.characterSkills.getSkillRank(SkillType.HISTORY));
			}
		} catch (IllegalArgumentException exception) {

		}
	}
	
	@UiHandler("historyDicePool")
	public void rollHistory(ClickEvent event) {
		this.showDiceRoll("History", this.characterQualities.getQualityScore(SkillType.HISTORY.getQualityType()), this.characterSkills.getSkillProficiencyLevel(SkillType.HISTORY), DiceRollType.SKILL);
	}

	private void updateCoreQualities() {
		this.strengthScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.STRENGTH)));
		this.agilityScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.AGILITY)));
		this.conditioningScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.CONDITIONING)));
		this.vitalityScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.VITALITY)));
		this.disciplineScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.DISCIPLINE)));
		this.intelligenceScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.INTELLIGENCE)));
		this.charismaScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.CHARISMA)));
	}
	
	private void updateQualities() {
		this.athleticismScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.ATHLETICISM)));
		this.physicalAcumenScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.PHYSICAL_ACUMEN)));
		this.fitnessScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.FITNESS)));
		this.willScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.WILL)));
		this.wisdomScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.WISDOM)));
		this.witScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.WIT)));
		this.presenceScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.PRESENCE)));
		this.reactionScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.REACTION)));
		this.physisScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.PHYSIS)));
		this.defenseRatingScore.setText(String.valueOf(this.characterQualities.getQualityScore(QualityType.DEFENSE_RATING)));
		this.healthPool.setText(String.valueOf(this.characterQualities.getHealthPool()));
		this.endurancePool.setText(String.valueOf(this.characterQualities.getEndurancePool()));

		if (this.characterQualities.getQualityScore(QualityType.STRENGTH) != 0) {
			this.strengthDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.STRENGTH)).toString());
		} else {
			this.strengthDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.AGILITY) != 0) {
			this.agilityDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.AGILITY)).toString());
		} else {
			this.agilityDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.CONDITIONING) != 0) {
			this.conditioningDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.CONDITIONING)).toString());
		} else {
			this.conditioningDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.VITALITY) != 0) {
			this.vitalityDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.VITALITY)).toString());
		} else {
			this.vitalityDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.DISCIPLINE) != 0) {
			this.disciplineDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.DISCIPLINE)).toString());
		} else {
			this.disciplineDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.INTELLIGENCE) != 0) {
			this.intelligenceDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.INTELLIGENCE)).toString());
		} else {
			this.intelligenceDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.CHARISMA) != 0) {
			this.charismaDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.CHARISMA)).toString());
		} else {
			this.charismaDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.ATHLETICISM) != 0) {
			this.athleticismDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.ATHLETICISM)).toString());
			this.movementRates.setAthleticismScore(this.characterQualities.getQualityScore(QualityType.ATHLETICISM));
			this.movementSwim.setText(String.valueOf(this.movementRates.getSwim()));
			this.movementCrawl.setText(String.valueOf(this.movementRates.getCrawl()));
			this.movementMonkeyRun.setText(String.valueOf(this.movementRates.getMonkeyRun()));
			this.movementWalk.setText(String.valueOf(this.movementRates.getWalk()));
			this.movementRun.setText(String.valueOf(this.movementRates.getRun()));
			this.movementSprint.setText(String.valueOf(this.movementRates.getSprint()));
			this.movementFly.setText(String.valueOf(this.movementRates.getFly()));
		} else {
			this.athleticismDicePool.setText("");
			this.movementRates.setAthleticismScore(0);
			this.movementSwim.setText("");
			this.movementCrawl.setText("");
			this.movementMonkeyRun.setText("");
			this.movementWalk.setText("");
			this.movementRun.setText("");
			this.movementSprint.setText("");
			this.movementFly.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.PHYSICAL_ACUMEN) != 0) {
			this.physicalAcumenDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.PHYSICAL_ACUMEN)).toString());
		} else {
			this.physicalAcumenDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.FITNESS) != 0) {
			this.fitnessDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.FITNESS)).toString());
		} else {
			this.fitnessDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.WILL) != 0) {
			this.willDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.WILL)).toString());
		} else {
			this.willDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.WISDOM) != 0) {
			this.wisdomDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.WISDOM)).toString());
		} else {
			this.wisdomDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.WIT) != 0) {
			this.witDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.WIT)).toString());
		} else {
			this.witDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.PRESENCE) != 0) {
			this.presenceDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.PRESENCE)).toString());
		} else {
			this.presenceDicePool.setText("");
		}
		if (this.characterQualities.getQualityScore(QualityType.REACTION) != 0) {
			this.reactionDicePool.setText(DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(QualityType.REACTION)).toString());
		} else {
			this.reactionDicePool.setText("");
		}
	}

	private void updateSkills(SkillType type) {
		switch (type) {
		case HISTORY:
			DicePoolType dicePoolType = DicePoolType.getDicePoolType(this.characterQualities.getQualityScore(type.getQualityType()));
			int modifier = this.characterSkills.getSkillProficiencyLevel(type);
			this.historyDicePool.setText(dicePoolType.toString() + '+' + String.valueOf(modifier));
		}
	}
	
	private void showDiceRoll(String title, int qualityScore, int modifier, DiceRollType diceRollType) {
		if (qualityScore != 0) {
			DicePoolType dicePool = DicePoolType.getDicePoolType(qualityScore);
			DiceRoll diceRoll = this.diceRoller.rollDicePool(title, dicePool, modifier, diceRollType);
			if (this.presenter != null) {
				this.presenter.onDiceRolled(diceRoll);
			}
			PopupPanel popupPanel = new PopupPanel(true, true);
			popupPanel.add(new DiceRollPopup(diceRoll));
			popupPanel.setGlassEnabled(true);
			popupPanel.center();
		}
	}
	
	@Override
	public Widget asWidget() {
		return this;
	}
}
